import os, subprocess, shutil
from datetime import datetime
from os import mkdir

if __name__ == '__main__':
    report_dir = f"reports/allure/allure_{datetime.now():%m%d%H%M%S}"
    mkdir(report_dir)
    shutil.rmtree("reports/tmp", ignore_errors=True)

    # 1. 跑用例 + 生成 Allure 原始数据
    subprocess.run([
        "pytest", "tests", "-v", "--alluredir", "reports/tmp"
    ], check=True)

    # # 2. 生成 / 自动打开 HTML 报告
    # subprocess.run([
    #     "allure", "generate", "reports/tmp", "-o", report_dir, "--clean"
    # ], check=True)
    # subprocess.run(["allure", "open", report_dir])